﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>异步任务=>宏任务与微任务示例代码</title>
</head>
<body>
    <script type="text/javascript">
        setTimeout(() => {
            console.log('t1')
        })
        new Promise((resolve, reject) => {
            console.log('t2')
            resolve()
        }).then(() => { })
        setTimeout(() => {
            console.log('t3')
        })
        new Promise((resolve, reject) => {
            console.log('t4')
            resolve()
        }).then(() => { })

        // 可以看出，微任务会先执行，当微任务执行完毕后，宏任务才会执行
        // 输出结果 t2 t4 t1 t3
    </script>
</body>
</html>
